﻿package Application.MapApplication.view.ui 
{
	import Application.MapApplication.MapApplicationFacade;
	import Application.MapApplication.model.PreloadingPry;
	
	import Application.MapApplication.def.Def;
	import def.XG;
	import Application.MapApplication.def.Manager;
	
	import fl.controls.ProgressBar;
	import fl.controls.ProgressBarDirection;
	import fl.controls.ProgressBarMode;
	
	import flash.display.MovieClip;
	import flash.display.Scene;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import flashx.textLayout.elements.OverflowPolicy;
	
	import Application.MapApplication.manager.SceneManager;
	import Application.MapApplication.manager.SourceManager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	/**
	 * 媒介，主要用于监听用户在UI上触发的事件，然后传递消息给controller或proxy。
	 * 同时也负责向UI上呈现数据
	 * @author ...
	 */
	public class StageMed extends Mediator
	{
		private var m_preloadingBar : ProgressBar;
		
		private var m_gameSource : SourceManager;
		
		private var m_gameFacde : MovieClip ;
		
		public function StageMed() 
		{
			//注册监听，从而获取UI上的事件
			super(Def.APPLICATIONFACADE,XG.stage);
			
			viewComponent.scaleMode = StageScaleMode.NO_SCALE;
			viewComponent.align = StageAlign.TOP_LEFT;
			
			m_gameSource = Manager.Source;
			
			Manager.Source.loadPreloadingSource(preloadingCallBack);
			
			viewComponent.addEventListener(Event.RESIZE,OnStageSizeChanged);
			
		}
		
		private function preloadingCallBack() : void
		{
			Manager.Scene.IntoScene(SceneManager.SceneId_PreLoading);
		}
		
		private function loadSourceCallBack() : void
		{
			m_gameFacde = m_gameSource.getMovieClip("game_facade");
		}
		
		override public function listNotificationInterests() : Array
		{
			return [];	
		}
		
		override public function handleNotification(notification : INotification) : void
		{
		}
		
		private function OnStageSizeChanged(evt : Event) : void
		{
			sendNotification(Def.STAGE_SIZE_CHANGED);
		}
	}	
}